package com.wyz.saas.common.notifice

import android.util.SparseArray
import java.util.*

enum class AtomDataRegistry {
    ;

    companion object {
        private val data = SparseArray<Any>()
        private val random = Random()

        fun <T> register(obj: T): Int {
            val index: Int = random.nextInt()
            data.put(index, obj)
            return index
        }

        fun <T> retrieve(index: Int): T {
            return retrieve(
                index,
                false
            )
        }

        fun <T> retrieve(index: Int, keep: Boolean): T {
            val obj = data[index]
            if (!keep) data.remove(index)
            return obj as T
        }
    }
}